package com.qlshouyu.len22.controller;

import com.qlshouyu.len22.model.User;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @author 高露 邮箱：<a href="egojit@qq.com">egojit@qq.com</a>
 * @since 2019-10-03 07:47
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    Map<String,User> users;

    @GetMapping("/{id}")
    public User detail(@PathVariable(name = "id")String id){
        return getUser(id);
    }
    @GetMapping
    public User detail1(@RequestParam(name = "id")String id){
        return getUser(id);
    }

    @PostMapping
    public User add(User user){
        return user;
    }
    @PostMapping("/add")
    public User add1(@RequestBody User user){
        return user;
    }

    private User getUser(String id){
        users=new HashMap<>();
        User user=new User("高露",30);
        User user1=new User("张三",31);
        users.put("1",user);
        users.put("2",user1);
        return users.get(id);
    }
}
